package com.qfedu.food.service.impl;

import com.qfedu.food.dao.CollectDao;
import com.qfedu.food.pojo.TCollect;
import com.qfedu.food.pojo.TFood;
import com.qfedu.food.service.intf.CollectService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
public class CollectServiceImpl implements CollectService {
    @Resource
    private CollectDao collectDao;
    @Override
    public Integer getUidByUsername(String username) {
        if (username != null) {
            return collectDao.getUidByUsername(username);
        }
        return 0 ;
    }

    @Override
    public Integer getFidByFname(String fname) {
        if (fname != null) {
            return collectDao.getFidByFname(fname);
        }
        return 0;
    }

    @Override
    public Integer addCollect(int uid, int fid) {
        if (uid != 0 && fid != 0){
            return collectDao.addCollect(uid, fid);
        }
        return 0;
    }

    @Override
    public Integer getCollect(int uid, int fid) {
        TCollect collect = collectDao.getCollect(uid, fid);
        if (collect==null){
            return 2;
        } else if (collect.getStatu()==1){
            return 1;
        }else if (collect.getStatu()==0){
            return 0;
        }
        return null;
    }

    @Override
    public Integer delCollectByUidAndFid(int uid) {
        if (uid != 0){
            return collectDao.delCollectByUidAndFid(uid);
        }
        return null;
    }

    @Override
    public Integer updateCollectByUidAndFid(int uid) {
        return collectDao.updateCollectByUidAndFid(uid);
    }

    @Override
    public List<Integer> getFidByUid(int uid) {
        if (uid != 0){
            return collectDao.getFidByUid(uid);
        }
        return null;
    }

    @Override
    public List<TFood> getFoodByid(List<Integer> fids) {
        if (fids.size() != 0){
            return collectDao.getFoodByid(fids);
        }
        return null;
    }
}
